<form id="userForm">
    <input type="hidden" name="userId" th:value="${user?.userId}">
    <div th:if="${user?.username != null}" class="form-group row">
        <label for="username" class="col-sm-2 col-form-label">用户名</label>
        <div class="col-sm-10">
            <input type="text" th:value="${user?.username}" readonly="readonly"
                   name="username" class="form-control" id="username"
                   placeholder="填写用户名" required>
            <div class="invalid-feedback">请填写用户名</div>
        </div>
    </div>
    <div th:if="${user?.username == null}" class="form-group row">
        <label for="username" class="col-sm-2 col-form-label">用户名</label>
        <div class="col-sm-10">
            <input type="text" th:value="${user?.username}"
                   name="username" class="form-control" id="username"
                   placeholder="填写用户名" required>
            <div class="invalid-feedback">请填写用户名</div>
        </div>
    </div>
    <div th:if="${user?.username == null}" class="form-group row">
        <label for="password" class="col-sm-2 col-form-label">密码</label>
        <div class="col-sm-10">
            <input type="password" name="password" class="form-control" id="password"
                   placeholder="请填写密码" required>
            <div class="invalid-feedback">请填写密码</div>
        </div>
    </div>
    <div th:if="${user?.username == null}" class="form-group row">
        <label for="confirmPassword" class="col-sm-2 col-form-label">确认密码</label>
        <div class="col-sm-10">
            <input type="password" name="confirmPassword" class="form-control" id="confirmPassword"
                   placeholder="请填写密码" required>
            <div class="invalid-feedback">请填写确认密码</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="email" class="col-sm-2 col-form-label">邮箱</label>
        <div class="col-sm-10">
            <input type="text" th:value="${user?.email}" name="email" class="form-control"
                   id="email"
                   placeholder="请填写邮箱" required>
            <div class="invalid-feedback">请填写邮箱</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="phone" class="col-sm-2 col-form-label">电话</label>
        <div class="col-sm-10">
            <input type="text" th:value="${user?.phone}" name="phone" class="form-control"
                   id="phone"
                   placeholder="请填写电话" required>
            <div class="invalid-feedback">请填写电话</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="sex" class="col-sm-2 col-form-label">性别</label>
        <div class="col-sm-10">
            <select id="sex" name="sex" class="form-control" required>
                <option th:selected="${user?.sex==1}" value="1">男</option>
                <option th:selected="${user?.sex==2}" value="2">女</option>
            </select>
            <div class="invalid-feedback">请选择性别</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="age" class="col-sm-2 col-form-label">年龄</label>
        <div class="col-sm-10">
            <input type="text" th:value="${user?.age}" name="age" class="form-control"
                   id="age"
                   placeholder="请填写年龄" required>
            <div class="invalid-feedback">请填写年龄</div>
        </div>
    </div>
</form>